<template>
    <el-dialog title="Teacher information input" :close-on-click-modal="false" :visible.sync="visible">
        <el-form :model="dataForm" ref="dataForm" label-width="130px">
            <el-form-item label="organizationName">
                <el-input v-model="dataForm.organizationName" placeholder="Fill in the unit organizationName"></el-input>
            </el-form-item>
            <el-form-item label="eduDepartmentId">
                <el-select v-model="dataForm.eduDepartmentId" placeholder="Fill in the unit eduDepartmentId">
                    <el-option
                      v-for="item in options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="jobEvaluation">
                <el-input v-model="dataForm.jobEvaluation" placeholder="Fill in the unit jobEvaluation"></el-input>
            </el-form-item>
            <el-form-item label="typeCertificates">
                <el-input v-model="dataForm.typeCertificates" placeholder="Fill in the unit typeCertificates"></el-input>
            </el-form-item>
            <el-form-item label="typeSubject">
                <el-input v-model="dataForm.typeSubject" placeholder="Fill in the unit typeSubject"></el-input>
            </el-form-item>
            <el-form-item label="currentSubject">
                <el-input v-model="dataForm.currentSubject" placeholder="Fill in the unit currentSubject"></el-input>
            </el-form-item>
            <el-form-item label="comment">
                <el-input type="textarea" v-model="dataForm.comment" placeholder="Fill in the unit comment"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">submit</el-button>
                <el-button @click="visible = false">cancel</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          sysUserId: '',
          organizationName: '',
          eduDepartmentId: '',
          jobEvaluation: '',
          typeCertificates: '',
          typeSubject: '',
          currentSubject: '',
          comment: ''
        },
        options: []
      }
    },
    methods: {
      init (id) {
        console.log(id)
        this.dataForm.sysUserId = id
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          this.queryEdudepartment()
        })
      },
      onSubmit () {
        console.log(this.dataForm)
        this.$http({
          url: this.$http.adornUrl(`/edu/teduteacherinfo/onSubmit`),
          method: 'post',
          data: this.dataForm
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: 'Operation succeeded',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      queryEdudepartment () {
        this.$http({
          url: this.$http.adornUrl(`/edu/tedudepartment/queryEdudepartment`),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.options = data.data
          } else {
            this.$message.error(data.msg)
          }
        })
      }
    }
  }
</script>